<template>
	<view class="content">
		<image src="https://travel-1306862033.cos.ap-chengdu.myqcloud.com/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E8%BF%9B%E5%85%A5%E9%A1%B5.jpg" class="bt-img"></image>
		<view class="button-block">
			<button size="mini" type="primary" class="bt-button" open-type="getPhoneNumber"
				@getphonenumber="getPhoneNumber">点击进入</button>
		</view>
	</view>
</template>

<script>
	import {
		loginAuth
	} from '@/api/customer.js';
	import {
		getStorage,
		setStorage
	} from '@/util/auth.js';
	import {
		login
	} from '@/util/login.js'
	export default {
		data() {
			return {
				userCode: '',
				mobileCode: ''
			}
		},
		methods: {
			/**
			 *
			 * 获取用户信息
			 */
			userLogin() {
				uni.login({
					provider: 'weixin',
					success: async (res) => {
						// console.log('登录获取code', res.code);
						if (res.errMsg == 'login:ok') {
							this.userCode = res.code;
							console.log(this.userCode);

						}
					},
				});
			},
			getPhoneNumber(e) {
				uni.showLoading({
					title: '加载中'
				});
					loginAuth({
					appid: '',
					userCode: this.userCode,
					mobileCode: e.detail.code					}).then((res) => {
						uni.hideLoading()
					if (res.code == 1) {
						console.log(res);
						//const state = res.msgState;
						const loginInfo = {
							token: res['access-token']
						};
						setStorage('login', loginInfo, 2678400);
						const user = res.data
						//登录
						login(user, res['access-token']);
						uni.switchTab({
							url: '/pages/home/index'
						})
					}

				}).catch((res)=>{
					console.log(res);
				});
			},

		},
		onLoad() {
			if (getStorage('login')) { //如果已经登录则跳转至首页
				uni.switchTab({
					url: '/pages/home/index'
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		.bt-img {
			height: 100%;
			width: 100%;
			position: absolute;
		}
		.button-block {
			position: fixed;
			width: 100%;
			bottom: 0;
			left: 0;
			height: 110rpx;
			padding-bottom: 55%;
			.bt-button {
				width: 320rpx;
				height: 70rpx;
				border: 1rpx solid #fff;
				color: #fff;
				border-color: #fff;
				border-radius: 40rpx;
				font-size: 28rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				background-color: #1aad1900;

			}
		}
	}
</style>
